package com.ls.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ls.entity.ResResult;
import com.ls.entity.User;
import com.ls.entity.UsersVO;
import com.ls.mapper.UserMapper;
import com.ls.utils.Md5Util;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-05-11
 */
@Service
public class UserServiceImpl extends ServiceImpl <UserMapper, User> implements UserService {

    @Override
    public ResResult login(UsersVO user) {
        QueryWrapper<User> qw = new QueryWrapper<User>();
        qw.eq("name",user.getName());
        qw.eq("password",Md5Util.encode ( user.getPassword () ));
        User one = this.baseMapper.selectOne(qw);
        if(one!=null){
            //返回用户编号，保存前端的cookie
            return ResResult.success(one.getId ());
        }
        return ResResult.error("用户名或密码错误");
    }
}
